<template>
  <page-header-wrapper :title="false">
    <a-card>
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="6" :sm="24">
              <a-form-item label="筛选">
                <a-input v-model="queryParam.queryCondition" placeholder="请输入" />
              </a-form-item>
            </a-col>
            <a-col :md="(!advanced && 8) || 24" :sm="24">
              <span
                class="table-page-search-submitButtons"
                :style="(advanced && { float: 'right', overflow: 'hidden' }) || {}"
              >
                <a-button type="primary" :loading="loading" @click="handleSearch(queryParam)">查询</a-button>
                <a-button style="margin-left: 8px" @click="() => (queryParam = {})">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <a-table ref="table" size="default" rowKey="key" :columns="columns" :data-source="loadData">
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>
        <span slot="status" slot-scope="text, record">
          <template>
            <a-tag color="#82af6f" v-if="record?.status == 1">已审核</a-tag>
            <a-tag color="#D15B47" v-else>待审核</a-tag>
          </template>
        </span>
        <span slot="action" slot-scope="text, record">
          <template> <a-tag color="#428bca" @click="handleDetail(record)">详情</a-tag> </template>
        </span>
      </a-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { omit } from 'lodash-es'
import { getGiftDetailStatListUsingPOST } from '@/api/api/tongjibaobiao.ts'
export default {
  name: 'presentDetail',
  data() {
    return {
      mdl: null,
      visible: false,
      loading: false,
      confirmLoading: false,
      // 高级搜索 展开/关闭
      advanced: false,
      pagination: {
        total: 0,
      },
      // 查询参数
      queryParam: {
        pageNo: 1,
        pageSize: 10,
        date: [this.$route.query.startTime, this.$route.query.endTime],
        queryCondition: '',
        status: '',
      },
      // 表头
      columns: [
        {
          title: '订单ID',
          dataIndex: 'orderId',
          width: 120,
        },
        {
          title: '赠送日期',
          dataIndex: 'orderDate',
          width: 120,
        },
        {
          title: '商品名',
          dataIndex: 'goodsName',
          width: 120,
        },
        {
          title: '品牌名称',
          dataIndex: 'brandName',
          width: 200,
        },
        {
          title: '一级分类名称',
          dataIndex: 'topName',
          width: 120,
        },
        {
          title: '二级分类名称',
          dataIndex: 'subName',
          width: 120,
        },
        {
          title: '串码1',
          dataIndex: 'phoneCode1',
          width: 120,
        },
        {
          title: '串码2',
          dataIndex: 'phoneCode2',
          width: 120,
        },
        {
          title: '赠送类型',
          dataIndex: 'saleType',
          width: 120,
        },
        {
          title: '成本(元)',
          dataIndex: 'cost',
          width: 120,
        },
        {
          title: '考核成本(元)',
          dataIndex: 'assCost',
          width: 120,
        },
        {
          title: '赠送人名称',
          dataIndex: 'empName',
          width: 120,
        },
        {
          title: '店面名称',
          dataIndex: 'storeName',
          width: 120,
        },
        {
          title: '会员名称',
          dataIndex: 'memName',
          width: 120,
        },
        {
          title: '会员手机号',
          dataIndex: 'phone',
          width: 120,
        },
        {
          title: '操作',
          dataIndex: 'action',
          width: '100px',
          fixed: 'right',
          scopedSlots: { customRender: 'action' },
        },
      ],

      // 加载数据方法 必须为 Promise 对象
      loadData: [],
    }
  },

  mounted() {
    this.handleSearch(this.queryParam)
  },
  methods: {
    handleSearch(val) {
      this.loading = true
      const params = {
        ...val,
        startTime: this.$route.query.startTime,
        endTime: this.$route.query.endTime,
      }
      //处理不同类型的请求赋值对应类型 id
      if (this.$route.query.storeId != {}) {
        params.storeId = this.$route.query.storeId
      } else if (this.$route.query.empId != {}) {
        params.empId = this.$route.query.empId
      }
      getGiftDetailStatListUsingPOST({ ...omit(params, ['date']) })
        .then((res) => {
          this.loadData = res.data.list
          this.loading = false
          this.queryParam.pageNo = this.pagination.current
          this.pagination = { ...this.pagination, total: Number(res.data.total) }
        })
        .catch((error) => {
          this.loading = false
          this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
        })
    },
    handleDetail(record) {
      this.$router.push({ path: `/cashier/profile/index/${record?.orderId}` })
    },
  },
}
</script>
